!macro __FlashUpdate

    StrCmp $FlashVersion "" SkipFlashUpdate
    StrCmp $CurrentFlashVersion "" BeginFlashUpdate
    StrCmp $FlashVersion $CurrentFlashVersion 0 BeginFlashUpdate

    ${DetailPrint} "The installed Flash version is still up-to-date."
    ${DetailPrint} "Flash update was skipped."
    Goto SkipFlashUpdate
  
    ;-------------------
  
    BeginFlashUpdate:
  
    ${DetailPrint} "Downloading Flash version $FlashVersion, please wait..."
    
    StrCmp $Hidden "0" ShowFlashProgress
    
    ${Download} "silent" "Flash version $FlashVersion" "$FlashURL" "$PLUGINSDIR\${FlashZIP}"
    
    Pop $R0
    StrCmp $R0 "OK" ExtractFlash
    ${DetailPrint} "Unable to download Flash at this time, will retry later."
    Goto SkipFlashUpdate
    
    ShowFlashProgress:
    
    ${Download} "banner" "Flash version $FlashVersion" "$FlashURL" "$PLUGINSDIR\${FlashZIP}"
    
    Pop $R0
    StrCmp $R0 "OK" ExtractFlash
    StrCmp $R0 "Cancelled" CancelledFlashDownload
    
    MessageBox MB_RETRYCANCEL|MB_ICONSTOP|MB_TOPMOST "Download failed: $R0$\nPlease check your internet connection and try again!" IDRETRY ShowFlashProgress
    Goto SkipFlashUpdate
  
    CancelledFlashDownload:
    MessageBox MB_OK|MB_ICONEXCLAMATION|MB_TOPMOST "Download was aborted by user!"
    Goto SkipFlashUpdate
    
    ExtractFlash:
    
    ${DetailPrint} "Extracting files, please wait..."

    CreateDirectory "$PLUGINSDIR\flash"
    
    !insertmacro ZIPDLL_EXTRACT "$PLUGINSDIR\${FlashZIP}" "$PLUGINSDIR\flash" "<ALL>"
    Pop $0
    
    StrCmp $0 "success" SuccessfullyExtractedFlash 0
    ${DetailPrint} "An error has occured while extracting the files ($0)"
    RMDir /r "$PLUGINSDIR\flash" 
    
    StrCmp $Hidden "1" SkipFlashUpdate
    
    MessageBox MB_RETRYCANCEL|MB_ICONSTOP|MB_TOPMOST "Extraction failed: $0$\nPlease check your user permissions and try again." IDRETRY ExtractFlash
    Goto SkipFlashUpdate
  
    SuccessfullyExtractedFlash:
    Delete "$PLUGINSDIR\${FlashZIP}"
    
    ;-------------------

    IfFileExists "$PLUGINSDIR\flash\gcswf32.dll" 0 MissingFlashFile
    Goto AllFlashFilesThere
  
    MissingFlashFile:
    ${DetailPrint} "Error: At least one required file is missing in the update!"
    RMDir /r "$PLUGINSDIR\flash"
    
    Goto SkipFlashUpdate
  
    AllFlashFilesThere: 
    
    StrCpy $UpgradeNeeded "yes"
    
    ;StrCpy $FlashVersion $Revision
    
    SkipFlashUpdate:
    
!macroend

!macro __FlashInstall

    StrCmp $FlashVersion "" SkipFlashInstall
    StrCmp $FlashVersion $CurrentFlashVersion SkipFlashInstall
    
    ${DetailPrint} "Installing Flash, please wait..."
    
    CopyFiles /SILENT "$PLUGINSDIR\flash\*.*" "$INSTDIR\chromium"
    IfErrors 0 FlashCopySuccessful
    ${DetailPrint} "Failed to copy Flash files to the install folder!" 
    RMDir /r "$PLUGINSDIR\flash"
        
    StrCmp $Hidden "1" SkipFlashInstall   
    
    FlashCopySuccessful:
    
    RMDir /r "$PLUGINSDIR\flash"
  
    ;-------------------

    ${DetailPrint} "Saving Flash version information, please wait..."

    ClearErrors
    FileOpen $0 "$INSTDIR\flash.ver" w
    IfErrors SkipWriteFlashVersion
    FileWrite $0 $FlashVersion
    FileClose $0
 
    SkipWriteFlashVersion:
    SkipFlashInstall:

!macroend

!define FlashUpdate "!insertmacro __FlashUpdate"
!define FlashInstall "!insertmacro __FlashInstall"